package ckw.database.model;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import ckw.managers.ModulesManager;

@Entity(name = "ckw.AdministratorToken")
public class AdministratorTokenExtended extends core.database.model.AdministratorToken {
	private static final long serialVersionUID = -2653100154724771474L;
	
	@ManyToOne
	@JoinColumn(name = "election", insertable = false, updatable = true)
	private ElectionNode election;

	public ElectionNode getElection() {
		return election;
	}

	public void setElection(ElectionNode election) {
		this.election = election;
	}

	public void deleteConnections() {
		this.getElection().getAdministratorTokens().remove(this);
		setElection(null);
		this.getMember().getTokens().remove(this);
		ModulesManager.getInstance().addOrUpdateMember(this.getMember());
		this.setMember(null);
	}
}
